package com.wind;

import java.util.ArrayList;
import java.util.List;

public class WindConstraintDefault extends WindConstraint {

	public String value = null;
	
	public String getCode() {
		return "wind.datastore.constraint.default";
	}
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public List<WindConstraintViolation> checkForInsert(WindEntity entity, WindTypeAttribute attribute) {
		return check(entity, attribute);
	}
	
	public List<WindConstraintViolation> checkForUpdate(WindEntity entity, WindTypeAttribute attribute) {	
		return check(entity, attribute);
	}
	
	private List<WindConstraintViolation> check(WindEntity entity, WindTypeAttribute attribute) {
		List<WindConstraintViolation> violations = new ArrayList<WindConstraintViolation>();
		
		String value = entity.getAttribute(attribute.getCode());
		
		if(value==null) {
			entity.setAttribute(attribute.getCode(), this.getValue());
		}
		
		return violations;
	}
}
